package com.founder.android.http;

import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;

import org.apache.http.HttpEntity;

/**
 * HTTP流返回包装类
 * @author chen_weihua
 *
 */
public class StreamCallbackWapper extends CallbackWrapper {
	
	private InputStream in;
	
	private Reader reader;

	public StreamCallbackWapper(ResponseListener callbackActivity) {
		super(callbackActivity);
	}
	
	@Override
	protected void setResult() throws Exception {
		HttpEntity entity = response.getEntity();
		in = entity.getContent();
		if (charset != null) {
			//使用字符流,防止乱码
			reader = new InputStreamReader(in, charset);
		}
	}
	
	@Override
	protected void onResponseSuccess() {
		if (charset != null) {
			callbackActivity.onResponseSuccess(response, reader);
		} else {
			callbackActivity.onResponseSuccess(response, in);
		}
	}

}
